home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / tip / doloop.tip < prev    next >
Text File  |  1993-09-15  |  2KB  |  87 lines

  1. % This macro source file is from the four volume series
  2. % "TeX in Practice" by Stephan von Bechtolsheim, published
  3. % 1993 by Springer-Verlag, New York.
  4. % Copyright 1993 Stephan von Bechtolsheim.
  5. % No warranty or liability is assumed.
  6. % This macro may be copied freely if no fees other than
  7. % media cost or shipping charges are charged and as long
  8. % as this copyright and the following source code itself
  9. % is not changed. Please see the series for further information.
  10. %
  11. % Version: 1.0
  12. % Date: May 1, 1993
  13. %
  14. %
  15. % This source code is documented in 27.1.8, p. III-412.
  16. % Original source in file "macros7.TEX", starting line 768.
  17. \wlog{L: "doloop.tip" ["macros7.TEX," l. 768, p. III-412]}%
  18. % This file DOES belong to format "texip."
  19. \catcode`\@ = 11
  20. \newcount\@DoLoopNesting
  21. \@DoLoopNesting = 0
  22. \newcount\@DoLoopLimit
  23. \newcount\@DoLoopLimitTwo
  24. \newcount\@DoLoopLimitThree
  25. \def\DoLoop #1#2#3#4#5{%
  26.     \global\advance\@DoLoopNesting by 1
  27.     \ifnum\@DoLoopNesting > 3
  28.         \errmessage{\string\DoLoop: nesting beyond three levels
  29.             is not supported.}%
  30.     \fi
  31.     \ifnum #3 = 0
  32.         \errmessage{\string\DoLoop: step value (parameter 3) is 0!}% 
  33.     \else
  34.         \ifcase\@DoLoopNesting
  35.         \or
  36.             \@DoLoop{#1}{#2}{#3}{#4}{#5}%
  37.             {\@DoLoopLimit}{\DoLoopBody}%
  38.         \or
  39.             \@DoLoop{#1}{#2}{#3}{#4}{#5}%
  40.             {\@DoLoopLimitTwo}{\DoLoopBodyTwo}%
  41.         \or
  42.             \@DoLoop{#1}{#2}{#3}{#4}{#5}%
  43.             {\@DoLoopLimitThree}{\DoLoopBodyThree}%
  44.         \fi
  45.     \fi
  46.     \global\advance\@DoLoopNesting by -1
  47. }
  48. \def\@DoLoop #1#2#3#4#5#6#7{%
  49.     \ifnum #3 > 0
  50.         #6 = #4% 
  51.         \advance#6 by 1
  52.         #1 = #2% 
  53.         \@DoLoopBodyPositive{#1}{#3}{#5}% 
  54.             {#6}{#7}%
  55.     \else
  56.         #6 = #4% 
  57.         \advance#6 by -1
  58.         #1 = #2% 
  59.         \@DoLoopBodyNegative{#1}{#3}{#5}% 
  60.             {#6}{#7}%
  61.     \fi
  62.     \@DoLoopIterate{#7}%
  63. }
  64. \def\@DoLoopBodyPositive #1#2#3#4#5{%
  65.     \def #5{% 
  66.         \ifnum #1 < #4\relax
  67.             #3% 
  68.             \advance #1 by #2% 
  69.     }%
  70. }
  71. \def\@DoLoopBodyNegative #1#2#3#4#5{%
  72.     \def #5{%
  73.         \ifnum #1 > #4\relax
  74.             #3% 
  75.             \advance #1 by #2% 
  76.     }% 
  77. }
  78. \def\@DoLoopIterate #1{%
  79.         #1\relax
  80.         \def\@DoLoopNext{\@DoLoopIterate{#1}}%
  81.     \else
  82.         \def\@DoLoopNext{\relax}%
  83.     \fi
  84.     \@DoLoopNext
  85. }
  86. \catcode`\@ = 12
  87.